{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8508f7e3",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1 引入pandas库\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "36351d58",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>order_id</th>\n",
       "      <th>quantity</th>\n",
       "      <th>item_name</th>\n",
       "      <th>choice_description</th>\n",
       "      <th>item_price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Chips and Fresh Tomato Salsa</td>\n",
       "      <td>NaN</td>\n",
       "      <td>$2.39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Izze</td>\n",
       "      <td>[Clementine]</td>\n",
       "      <td>$3.39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Nantucket Nectar</td>\n",
       "      <td>[Apple]</td>\n",
       "      <td>$3.39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Chips and Tomatillo-Green Chili Salsa</td>\n",
       "      <td>NaN</td>\n",
       "      <td>$2.39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>Chicken Bowl</td>\n",
       "      <td>[Tomatillo-Red Chili Salsa (Hot), [Black Beans...</td>\n",
       "      <td>$16.98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4617</th>\n",
       "      <td>1833</td>\n",
       "      <td>1</td>\n",
       "      <td>Steak Burrito</td>\n",
       "      <td>[Fresh Tomato Salsa, [Rice, Black Beans, Sour ...</td>\n",
       "      <td>$11.75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4618</th>\n",
       "      <td>1833</td>\n",
       "      <td>1</td>\n",
       "      <td>Steak Burrito</td>\n",
       "      <td>[Fresh Tomato Salsa, [Rice, Sour Cream, Cheese...</td>\n",
       "      <td>$11.75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4619</th>\n",
       "      <td>1834</td>\n",
       "      <td>1</td>\n",
       "      <td>Chicken Salad Bowl</td>\n",
       "      <td>[Fresh Tomato Salsa, [Fajita Vegetables, Pinto...</td>\n",
       "      <td>$11.25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4620</th>\n",
       "      <td>1834</td>\n",
       "      <td>1</td>\n",
       "      <td>Chicken Salad Bowl</td>\n",
       "      <td>[Fresh Tomato Salsa, [Fajita Vegetables, Lettu...</td>\n",
       "      <td>$8.75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4621</th>\n",
       "      <td>1834</td>\n",
       "      <td>1</td>\n",
       "      <td>Chicken Salad Bowl</td>\n",
       "      <td>[Fresh Tomato Salsa, [Fajita Vegetables, Pinto...</td>\n",
       "      <td>$8.75</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4622 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      order_id  quantity                              item_name  \\\n",
       "0            1         1           Chips and Fresh Tomato Salsa   \n",
       "1            1         1                                   Izze   \n",
       "2            1         1                       Nantucket Nectar   \n",
       "3            1         1  Chips and Tomatillo-Green Chili Salsa   \n",
       "4            2         2                           Chicken Bowl   \n",
       "...        ...       ...                                    ...   \n",
       "4617      1833         1                          Steak Burrito   \n",
       "4618      1833         1                          Steak Burrito   \n",
       "4619      1834         1                     Chicken Salad Bowl   \n",
       "4620      1834         1                     Chicken Salad Bowl   \n",
       "4621      1834         1                     Chicken Salad Bowl   \n",
       "\n",
       "                                     choice_description item_price  \n",
       "0                                                   NaN     $2.39   \n",
       "1                                          [Clementine]     $3.39   \n",
       "2                                               [Apple]     $3.39   \n",
       "3                                                   NaN     $2.39   \n",
       "4     [Tomatillo-Red Chili Salsa (Hot), [Black Beans...    $16.98   \n",
       "...                                                 ...        ...  \n",
       "4617  [Fresh Tomato Salsa, [Rice, Black Beans, Sour ...    $11.75   \n",
       "4618  [Fresh Tomato Salsa, [Rice, Sour Cream, Cheese...    $11.75   \n",
       "4619  [Fresh Tomato Salsa, [Fajita Vegetables, Pinto...    $11.25   \n",
       "4620  [Fresh Tomato Salsa, [Fajita Vegetables, Lettu...     $8.75   \n",
       "4621  [Fresh Tomato Salsa, [Fajita Vegetables, Pinto...     $8.75   \n",
       "\n",
       "[4622 rows x 5 columns]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 2 导入附件中的文件（外部文件）为DataFrame\n",
    "df1= pd.read_csv(\"./saleGoods.tsv\",sep=\"\\t\")\n",
    "\n",
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "a34cc54a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>order_id</th>\n",
       "      <th>quantity</th>\n",
       "      <th>item_name</th>\n",
       "      <th>choice_description</th>\n",
       "      <th>item_price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Chips and Fresh Tomato Salsa</td>\n",
       "      <td>NaN</td>\n",
       "      <td>$2.39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Izze</td>\n",
       "      <td>[Clementine]</td>\n",
       "      <td>$3.39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Nantucket Nectar</td>\n",
       "      <td>[Apple]</td>\n",
       "      <td>$3.39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Chips and Tomatillo-Green Chili Salsa</td>\n",
       "      <td>NaN</td>\n",
       "      <td>$2.39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>Chicken Bowl</td>\n",
       "      <td>[Tomatillo-Red Chili Salsa (Hot), [Black Beans...</td>\n",
       "      <td>$16.98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>Chicken Bowl</td>\n",
       "      <td>[Fresh Tomato Salsa (Mild), [Rice, Cheese, Sou...</td>\n",
       "      <td>$10.98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>Side of Chips</td>\n",
       "      <td>NaN</td>\n",
       "      <td>$1.69</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>Steak Burrito</td>\n",
       "      <td>[Tomatillo Red Chili Salsa, [Fajita Vegetables...</td>\n",
       "      <td>$11.75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>Steak Soft Tacos</td>\n",
       "      <td>[Tomatillo Green Chili Salsa, [Pinto Beans, Ch...</td>\n",
       "      <td>$9.25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>Steak Burrito</td>\n",
       "      <td>[Fresh Tomato Salsa, [Rice, Black Beans, Pinto...</td>\n",
       "      <td>$9.25</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   order_id  quantity                              item_name  \\\n",
       "0         1         1           Chips and Fresh Tomato Salsa   \n",
       "1         1         1                                   Izze   \n",
       "2         1         1                       Nantucket Nectar   \n",
       "3         1         1  Chips and Tomatillo-Green Chili Salsa   \n",
       "4         2         2                           Chicken Bowl   \n",
       "5         3         1                           Chicken Bowl   \n",
       "6         3         1                          Side of Chips   \n",
       "7         4         1                          Steak Burrito   \n",
       "8         4         1                       Steak Soft Tacos   \n",
       "9         5         1                          Steak Burrito   \n",
       "\n",
       "                                  choice_description item_price  \n",
       "0                                                NaN     $2.39   \n",
       "1                                       [Clementine]     $3.39   \n",
       "2                                            [Apple]     $3.39   \n",
       "3                                                NaN     $2.39   \n",
       "4  [Tomatillo-Red Chili Salsa (Hot), [Black Beans...    $16.98   \n",
       "5  [Fresh Tomato Salsa (Mild), [Rice, Cheese, Sou...    $10.98   \n",
       "6                                                NaN     $1.69   \n",
       "7  [Tomatillo Red Chili Salsa, [Fajita Vegetables...    $11.75   \n",
       "8  [Tomatillo Green Chili Salsa, [Pinto Beans, Ch...     $9.25   \n",
       "9  [Fresh Tomato Salsa, [Rice, Black Beans, Pinto...     $9.25   "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 3 取这个DataFrame的前10行内容看一看\n",
    "df1.head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "31185a0f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 4 打印出这个DataFrame中有多少个列(columns)\n",
    "df1.columns.size"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "af044675",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['order_id', 'quantity', 'item_name', 'choice_description',\n",
       "       'item_price'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 5 显示这个DataFrame的所有的列（字段）名称\n",
    "df1.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "87d57d8f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RangeIndex(start=0, stop=4622, step=1)"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 6 显示这个DataFrame的索引\n",
    "df1.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "c28f5678",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>order_id</th>\n",
       "      <th>quantity</th>\n",
       "      <th>item_name</th>\n",
       "      <th>choice_description</th>\n",
       "      <th>item_price</th>\n",
       "      <th>boss</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Chips and Fresh Tomato Salsa</td>\n",
       "      <td>NaN</td>\n",
       "      <td>$2.39</td>\n",
       "      <td>box</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Izze</td>\n",
       "      <td>[Clementine]</td>\n",
       "      <td>$3.39</td>\n",
       "      <td>box</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Nantucket Nectar</td>\n",
       "      <td>[Apple]</td>\n",
       "      <td>$3.39</td>\n",
       "      <td>box</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Chips and Tomatillo-Green Chili Salsa</td>\n",
       "      <td>NaN</td>\n",
       "      <td>$2.39</td>\n",
       "      <td>box</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>Chicken Bowl</td>\n",
       "      <td>[Tomatillo-Red Chili Salsa (Hot), [Black Beans...</td>\n",
       "      <td>$16.98</td>\n",
       "      <td>box</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4617</th>\n",
       "      <td>1833</td>\n",
       "      <td>1</td>\n",
       "      <td>Steak Burrito</td>\n",
       "      <td>[Fresh Tomato Salsa, [Rice, Black Beans, Sour ...</td>\n",
       "      <td>$11.75</td>\n",
       "      <td>box</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4618</th>\n",
       "      <td>1833</td>\n",
       "      <td>1</td>\n",
       "      <td>Steak Burrito</td>\n",
       "      <td>[Fresh Tomato Salsa, [Rice, Sour Cream, Cheese...</td>\n",
       "      <td>$11.75</td>\n",
       "      <td>box</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4619</th>\n",
       "      <td>1834</td>\n",
       "      <td>1</td>\n",
       "      <td>Chicken Salad Bowl</td>\n",
       "      <td>[Fresh Tomato Salsa, [Fajita Vegetables, Pinto...</td>\n",
       "      <td>$11.25</td>\n",
       "      <td>box</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4620</th>\n",
       "      <td>1834</td>\n",
       "      <td>1</td>\n",
       "      <td>Chicken Salad Bowl</td>\n",
       "      <td>[Fresh Tomato Salsa, [Fajita Vegetables, Lettu...</td>\n",
       "      <td>$8.75</td>\n",
       "      <td>box</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4621</th>\n",
       "      <td>1834</td>\n",
       "      <td>1</td>\n",
       "      <td>Chicken Salad Bowl</td>\n",
       "      <td>[Fresh Tomato Salsa, [Fajita Vegetables, Pinto...</td>\n",
       "      <td>$8.75</td>\n",
       "      <td>box</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4622 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      order_id  quantity                              item_name  \\\n",
       "0            1         1           Chips and Fresh Tomato Salsa   \n",
       "1            1         1                                   Izze   \n",
       "2            1         1                       Nantucket Nectar   \n",
       "3            1         1  Chips and Tomatillo-Green Chili Salsa   \n",
       "4            2         2                           Chicken Bowl   \n",
       "...        ...       ...                                    ...   \n",
       "4617      1833         1                          Steak Burrito   \n",
       "4618      1833         1                          Steak Burrito   \n",
       "4619      1834         1                     Chicken Salad Bowl   \n",
       "4620      1834         1                     Chicken Salad Bowl   \n",
       "4621      1834         1                     Chicken Salad Bowl   \n",
       "\n",
       "                                     choice_description item_price boss  \n",
       "0                                                   NaN     $2.39   box  \n",
       "1                                          [Clementine]     $3.39   box  \n",
       "2                                               [Apple]     $3.39   box  \n",
       "3                                                   NaN     $2.39   box  \n",
       "4     [Tomatillo-Red Chili Salsa (Hot), [Black Beans...    $16.98   box  \n",
       "...                                                 ...        ...  ...  \n",
       "4617  [Fresh Tomato Salsa, [Rice, Black Beans, Sour ...    $11.75   box  \n",
       "4618  [Fresh Tomato Salsa, [Rice, Sour Cream, Cheese...    $11.75   box  \n",
       "4619  [Fresh Tomato Salsa, [Fajita Vegetables, Pinto...    $11.25   box  \n",
       "4620  [Fresh Tomato Salsa, [Fajita Vegetables, Lettu...     $8.75   box  \n",
       "4621  [Fresh Tomato Salsa, [Fajita Vegetables, Pinto...     $8.75   box  \n",
       "\n",
       "[4622 rows x 6 columns]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 7 给上一题的DataFrame增加1个字段名为“boss”，值为你的名字\n",
    "df1[\"boss\"]=\"box\"\n",
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "5ccef070",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>order_id</th>\n",
       "      <th>quantity</th>\n",
       "      <th>item_name</th>\n",
       "      <th>choice_description</th>\n",
       "      <th>item_price</th>\n",
       "      <th>boss</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1254</th>\n",
       "      <td>511</td>\n",
       "      <td>4</td>\n",
       "      <td>Chicken Burrito</td>\n",
       "      <td>[Fresh Tomato Salsa, [Fajita Vegetables, Rice,...</td>\n",
       "      <td>$35.00</td>\n",
       "      <td>box</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1257</th>\n",
       "      <td>511</td>\n",
       "      <td>4</td>\n",
       "      <td>Chips and Fresh Tomato Salsa</td>\n",
       "      <td>NaN</td>\n",
       "      <td>$11.80</td>\n",
       "      <td>box</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1425</th>\n",
       "      <td>577</td>\n",
       "      <td>4</td>\n",
       "      <td>Bottled Water</td>\n",
       "      <td>NaN</td>\n",
       "      <td>$6.00</td>\n",
       "      <td>box</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1880</th>\n",
       "      <td>759</td>\n",
       "      <td>4</td>\n",
       "      <td>Bottled Water</td>\n",
       "      <td>NaN</td>\n",
       "      <td>$6.00</td>\n",
       "      <td>box</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2235</th>\n",
       "      <td>901</td>\n",
       "      <td>4</td>\n",
       "      <td>Canned Soda</td>\n",
       "      <td>[Sprite]</td>\n",
       "      <td>$4.36</td>\n",
       "      <td>box</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2441</th>\n",
       "      <td>970</td>\n",
       "      <td>5</td>\n",
       "      <td>Bottled Water</td>\n",
       "      <td>NaN</td>\n",
       "      <td>$7.50</td>\n",
       "      <td>box</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3598</th>\n",
       "      <td>1443</td>\n",
       "      <td>15</td>\n",
       "      <td>Chips and Fresh Tomato Salsa</td>\n",
       "      <td>NaN</td>\n",
       "      <td>$44.25</td>\n",
       "      <td>box</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3599</th>\n",
       "      <td>1443</td>\n",
       "      <td>7</td>\n",
       "      <td>Bottled Water</td>\n",
       "      <td>NaN</td>\n",
       "      <td>$10.50</td>\n",
       "      <td>box</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3602</th>\n",
       "      <td>1443</td>\n",
       "      <td>4</td>\n",
       "      <td>Chicken Burrito</td>\n",
       "      <td>[Fresh Tomato Salsa, [Rice, Black Beans, Chees...</td>\n",
       "      <td>$35.00</td>\n",
       "      <td>box</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3887</th>\n",
       "      <td>1559</td>\n",
       "      <td>8</td>\n",
       "      <td>Side of Chips</td>\n",
       "      <td>NaN</td>\n",
       "      <td>$13.52</td>\n",
       "      <td>box</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3973</th>\n",
       "      <td>1592</td>\n",
       "      <td>4</td>\n",
       "      <td>Canned Soft Drink</td>\n",
       "      <td>[Coke]</td>\n",
       "      <td>$5.00</td>\n",
       "      <td>box</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4152</th>\n",
       "      <td>1660</td>\n",
       "      <td>10</td>\n",
       "      <td>Bottled Water</td>\n",
       "      <td>NaN</td>\n",
       "      <td>$15.00</td>\n",
       "      <td>box</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4489</th>\n",
       "      <td>1786</td>\n",
       "      <td>4</td>\n",
       "      <td>Chips and Guacamole</td>\n",
       "      <td>NaN</td>\n",
       "      <td>$17.80</td>\n",
       "      <td>box</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4490</th>\n",
       "      <td>1786</td>\n",
       "      <td>4</td>\n",
       "      <td>Canned Soft Drink</td>\n",
       "      <td>[Coke]</td>\n",
       "      <td>$5.00</td>\n",
       "      <td>box</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4491</th>\n",
       "      <td>1786</td>\n",
       "      <td>4</td>\n",
       "      <td>Canned Soft Drink</td>\n",
       "      <td>[Sprite]</td>\n",
       "      <td>$5.00</td>\n",
       "      <td>box</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      order_id  quantity                     item_name  \\\n",
       "1254       511         4               Chicken Burrito   \n",
       "1257       511         4  Chips and Fresh Tomato Salsa   \n",
       "1425       577         4                 Bottled Water   \n",
       "1880       759         4                 Bottled Water   \n",
       "2235       901         4                   Canned Soda   \n",
       "2441       970         5                 Bottled Water   \n",
       "3598      1443        15  Chips and Fresh Tomato Salsa   \n",
       "3599      1443         7                 Bottled Water   \n",
       "3602      1443         4               Chicken Burrito   \n",
       "3887      1559         8                 Side of Chips   \n",
       "3973      1592         4             Canned Soft Drink   \n",
       "4152      1660        10                 Bottled Water   \n",
       "4489      1786         4           Chips and Guacamole   \n",
       "4490      1786         4             Canned Soft Drink   \n",
       "4491      1786         4             Canned Soft Drink   \n",
       "\n",
       "                                     choice_description item_price boss  \n",
       "1254  [Fresh Tomato Salsa, [Fajita Vegetables, Rice,...    $35.00   box  \n",
       "1257                                                NaN    $11.80   box  \n",
       "1425                                                NaN     $6.00   box  \n",
       "1880                                                NaN     $6.00   box  \n",
       "2235                                           [Sprite]     $4.36   box  \n",
       "2441                                                NaN     $7.50   box  \n",
       "3598                                                NaN    $44.25   box  \n",
       "3599                                                NaN    $10.50   box  \n",
       "3602  [Fresh Tomato Salsa, [Rice, Black Beans, Chees...    $35.00   box  \n",
       "3887                                                NaN    $13.52   box  \n",
       "3973                                             [Coke]     $5.00   box  \n",
       "4152                                                NaN    $15.00   box  \n",
       "4489                                                NaN    $17.80   box  \n",
       "4490                                             [Coke]     $5.00   box  \n",
       "4491                                           [Sprite]     $5.00   box  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 8 查询出quantity字段值大于3的所有列的数据\n",
    "df2=df1.loc[df1['quantity']>3]\n",
    "df2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "1e4dd040",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "15"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2.index.size"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "34b0c781",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Engine(mysql+pymysql://root:***@127.0.0.1:3306/testdb?charset=utf8)\n"
     ]
    }
   ],
   "source": [
    "# 9 把上一题查询结果保存到mysql数据库中，表名为“salegoods”\n",
    "\n",
    "from sqlalchemy import create_engine\n",
    "# 创建一个MySQL连接器，用户名为root，密码为1234\n",
    "# 地址为127.0.0.1，数据库名称为testdb，编码为UTF-8\n",
    "engine = create_engine('mysql+pymysql://root:123456@127.0.0.1:3306/testdb?charset=utf8')\n",
    "print(engine)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "738fbb89",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "15"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2.to_sql('salegoods',con=engine,if_exists='replace')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cf39e015",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
